import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/system-service/user/pageUser',
  get = '/system-service/user/getUserDetails',
  save='/system-service/user/save',
  edit='/system-service/user/update',
  getUserRole = '/system-service/tenantUser/listUserRole',
  deleteUser = '/system-service/user/delete',
  deleteBatch = '/system-service/user/deleteBatch',
  importExcel = '/system-service/user/importExcel',
  exportXls = '/system-service/user/exportXls',
  recycleBinList = '/system-service/user/recycleBin',
  recoverRecycleBin = '/system-service/user/recoverRecycleBin',
  deleteRecycleBin = '/system-service/user/deleteRecycleBin',
  allRolesList = '/system-service/role/listAllRole',
  allTenantList = '/system-service/tenant/listAll',
  allPostList = '/system-service/position/listAll',
  listUserDept = '/system-service/user/listUserDept',
  frozenBatch = '/system-service/user/frozenBatch',
  syncUser = '/act/process/extActProcess/doSyncUser',
  listTenant = '/system-service/user/profile/listTenant',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => 
  defHttp.get({url: Api.list, params});

/**
 * @param params
 */
export const getUserDetails = (params) => 
  defHttp.get({url: Api.get, params});


/**
 * 删除用户
 */
export const deleteUser = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteUser, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除用户
 * @param params
 */
export const batchDeleteUser = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新用户
 * @param params
 */
export const saveOrUpdateUser = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 获取全部角色
 * @param params
 */
export const getAllRolesList = (params) =>
  defHttp.get({url: Api.allRolesList, params});
/**
 * 获取全部租户
 */
export const getAllTenantList = (params) =>
  defHttp.get({url: Api.allTenantList, params});
/**
 * 获取指定用户负责部门
 */
export const getUserDeptList = (params) =>
  defHttp.get({url: Api.listUserDept, params},{successMessageMode: 'none'});
/**
 * 获取全部职务
 */
export const getAllPostList = (params) => {
  return new Promise((resolve) => {
    defHttp.get({url: Api.allPostList, params}).then(res => {
      resolve(res.records)
    });
  })
}
/**
 * 回收站列表
 * @param params
 */
export const getRecycleBinList = (params) =>
  defHttp.get({url: Api.recycleBinList, params});
/**
 * 回收站还原
 * @param params
 */
export const recoverRecycleBin = (params,handleSuccess) =>{
  return defHttp.put({url: Api.recoverRecycleBin, params}).then(() => {
    handleSuccess();
  });
}
/**
 * 回收站删除
 * @param params
 */
export const deleteRecycleBin = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteRecycleBin, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 冻结解冻
 * @param params
 */
export const frozenBatch = (params,handleSuccess) => {
  return defHttp.put({url: Api.frozenBatch, params}).then(() => {
    handleSuccess();
  });
}

/**
 * 用户同步流程
 * @param params
 */
export const syncUser = () =>
  defHttp.put({url: Api.syncUser});


export const listLoginUserTenant = () => {
  return defHttp.get({url: Api.listTenant, params: {}});
}

  